﻿

Imports ADOEntityAMLO101
Imports ADOEntityAMLO102
Imports ADOEntityAMLO103
Partial Class AMLO_frmPopupSelectPrint
    Inherits System.Web.UI.Page
    'Dim RRPTEntity As RPTEntities
    Dim intBeforeItemIndex As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not (IsPostBack) Then
            hdfTempRPTSEQ.Value = Request.Item("RPTSEQ")
            hdfTempRptType.Value = Request.Item("RPTTYPE")
            hdfStatus.Value = Request.Item("StatusPrint")
        End If

        Dim strRptSeq As String = hdfTempRPTSEQ.Value
        Dim strRptType As String = hdfTempRptType.Value
      
        If (strRptType = "1") Then
            If Not (strRptSeq = "") Then

                Dim AMLO101Entity As AMLO101Entities = New AMLO101Entities

                Dim sql = (From tblRRPT In AMLO101Entity.AMLO101 Join tblRRPTDEtail In AMLO101Entity.AMLODETAIL101 On tblRRPT.RPTSEQ Equals tblRRPTDEtail.RPTSEQ
                        Where tblRRPT.RPTSEQ = strRptSeq Select tblRRPTDEtail.RPTSEQ, tblRRPTDEtail.RPTIDX, tblRRPTDEtail.RPTIDXTYPE, tblRRPT.RPTNO, tblRRPT.RPTTYPE, tblRRPTDEtail.FIRSTNAME, tblRRPTDEtail.MIDNAME, tblRRPTDEtail.LASTNAME).ToList
                Dim countRow As Integer = sql.Count
                If (countRow > 1) Then
                    grdAmlo.DataSource = sql.Where(Function(t) t.RPTIDX <> 1)
                    grdAmlo.DataBind()
                    btnPrintReport.Visible = False
                Else
                    btnPrintReport.Visible = True
                    Dim param As String = "{ 'RPTSEQ' : '" & sql(0).RPTSEQ & "','RPTIDX' : '" & sql(0).RPTIDX & "'}"
                    'Dim param As String = "{ 'RPTSEQ' : '" & sql(0).RPTSEQ & "','RPTStatus' : 'CheckLoad','RPTIDX' : '" & sql(0).RPTIDX & "'}"

                    'ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", _
                    '                                    "window.showModalDialog('../Form/RptAmlo1_01.aspx?RPTSEQ=" & sql(0).RPTSEQ & "&" _
                    '                                            & "RPTIDX=" & sql(0).RPTIDX & "'" _
                    '                                            & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)

                    btnPrintReport.Attributes.Add("onclick", _
                                "window.showModalDialog('../Form/RptAmlo1_01.aspx?RPTSEQ=" & sql(0).RPTSEQ & "&" _
                                                                & "RPTIDX=" & sql(0).RPTIDX & "'" _
                                                                & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')")


                    'btnPrintReport.Attributes.Add("onclick", _
                    '            "OpenWindowWithPost('../Form/RptAmlo1_01.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','AMLO_101', " + param + ");")
                End If
                If (sql(0).RPTTYPE = 1) Then
                    lblAMLO.Text = "ออกรายงาน ปปง.1-01"
                ElseIf (sql(0).RPTTYPE = 2) Then
                    lblAMLO.Text = "ออกรายงาน ปปง.1-02"
                ElseIf (sql(0).RPTTYPE = 3) Then
                    lblAMLO.Text = "ออกรายงาน ปปง.1-03"
                End If
            Else
                btnPrintReport.Visible = True
                'Dim param As String = "{ 'RPTSEQ' : '" & "" & "','RPTIDX' : '" & "" & "'}"
                'btnPrintReport.Attributes.Add("onclick", _
                '            "OpenWindowWithPost('../Form/RptAmlo1_01.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','AMLO_101', " + param + ");")
                'ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", _
                '                                                   "window.showModalDialog('../Form/RptAmlo1_01.aspx?RPTSEQ=" & "" & "&" _
                '                                                           & "RPTIDX=" & "" & "'" _
                '                                                           & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)

                btnPrintReport.Attributes.Add("onclick", _
                              "window.showModalDialog('../Form/RptAmlo1_01.aspx?RPTSEQ=" & "" & "&" _
                                                              & "RPTIDX=" & "" & "'" _
                                                              & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')")


            End If
        ElseIf (strRptType = "2") Then
            If Not (strRptSeq = "") Then
                Dim AMLO102Entity As AMLO102Entities = New AMLO102Entities

                Dim sql = (From tblRRPT In AMLO102Entity.AMLO102 Join tblRRPTDEtail In AMLO102Entity.AMLODETAIL102 On tblRRPT.RPTSEQ Equals tblRRPTDEtail.RPTSEQ
                        Where tblRRPT.RPTSEQ = strRptSeq Select tblRRPTDEtail.RPTSEQ, tblRRPTDEtail.RPTIDX, tblRRPTDEtail.RPTIDXTYPE, tblRRPT.RPTNO, tblRRPT.RPTTYPE, tblRRPTDEtail.FIRSTNAME, tblRRPTDEtail.MIDNAME, tblRRPTDEtail.LASTNAME).ToList
                Dim countRow As Integer = sql.Count
                If (countRow > 1) Then
                    grdAmlo.DataSource = sql.Where(Function(t) t.RPTIDX <> 1)
                    grdAmlo.DataBind()
                    btnPrintReport.Visible = False
                Else

                    btnPrintReport.Visible = True
                    'Dim param As String = "{ 'RPTSEQ' : '" & sql(0).RPTSEQ & "','RPTIDX' : '" & sql(0).RPTIDX & "'}"
                    'btnPrintReport.Attributes.Add("onclick", _
                    '            "OpenWindowWithPost('../Form/RptAmlo1_02.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','AMLO_102', " + param + ");")

                    'ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", _
                    '                                    "window.showModalDialog('../Form/RptAmlo1_02.aspx?RPTSEQ=" & sql(0).RPTSEQ & "&" _
                    '                                            & "RPTIDX=" & sql(0).RPTIDX & "'" _
                    '                                            & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)
                    btnPrintReport.Attributes.Add("onclick", _
                              "window.showModalDialog('../Form/RptAmlo1_02.aspx?RPTSEQ=" & sql(0).RPTSEQ & "&" _
                                                              & "RPTIDX=" & sql(0).RPTIDX & "'" _
                                                              & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')")


                End If
                If (sql(0).RPTTYPE = 1) Then
                    lblAMLO.Text = "ออกรายงาน ปปง.1-01"
                ElseIf (sql(0).RPTTYPE = 2) Then
                    lblAMLO.Text = "ออกรายงาน ปปง.1-02"
                ElseIf (sql(0).RPTTYPE = 3) Then
                    lblAMLO.Text = "ออกรายงาน ปปง.1-03"
                End If
            Else
                btnPrintReport.Visible = True
                'Dim param As String = "{ 'RPTSEQ' : '" & "" & "','RPTIDX' : '" & "" & "'}"
                'btnPrintReport.Attributes.Add("onclick", _
                '            "OpenWindowWithPost('../Form/RptAmlo1_02.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','AMLO_102', " + param + ");")
                'ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", _
                '                                     "window.showModalDialog('../Form/RptAmlo1_02.aspx?RPTSEQ=" & "" & "&" _
                '                                             & "RPTIDX=" & "" & "'" _
                '                                             & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)

                btnPrintReport.Attributes.Add("onclick", _
                            "window.showModalDialog('../Form/RptAmlo1_02.aspx?RPTSEQ=" & "" & "&" _
                                                            & "RPTIDX=" & "" & "'" _
                                                            & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')")


            End If
        ElseIf (strRptType = "3") Then
            If Not (strRptSeq = "") Then
                Dim AMLO103Entity As AMLO103Entities = New AMLO103Entities

                Dim sql = (From tblRRPT In AMLO103Entity.AMLO103 Join tblRRPTDEtail In AMLO103Entity.AMLODETAIL103 On tblRRPT.RPTSEQ Equals tblRRPTDEtail.RPTSEQ
                        Where tblRRPT.RPTSEQ = strRptSeq Select tblRRPTDEtail.RPTSEQ, tblRRPTDEtail.RPTIDX, tblRRPTDEtail.RPTIDXTYPE, tblRRPT.RPTNO, tblRRPT.RPTTYPE, tblRRPTDEtail.FIRSTNAME, tblRRPTDEtail.MIDNAME, tblRRPTDEtail.LASTNAME).ToList
                Dim countRow As Integer = sql.Count
                If (countRow > 1) Then
                    grdAmlo.DataSource = sql.Where(Function(t) t.RPTIDX <> 1)
                    grdAmlo.DataBind()
                    btnPrintReport.Visible = False
                Else
                    Visible = True
                    'Dim param As String = "{ 'RPTSEQ' : '" & sql(0).RPTSEQ & "','RPTIDX' : '" & sql(0).RPTIDX & "'}"
                    'btnPrintReport.Attributes.Add("onclick", _
                    '            "OpenWindowWithPost('../Form/RptAmlo1_03.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','AMLO_103', " + param + ");")

                    'ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", _
                    '                                                      "window.showModalDialog('../Form/RptAmlo1_03.aspx?RPTSEQ=" & sql(0).RPTSEQ & "&" _
                    '                                                              & "RPTIDX=" & sql(0).RPTIDX & "'" _
                    '                                                              & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)
                    btnPrintReport.Attributes.Add("onclick", _
                           "window.showModalDialog('../Form/RptAmlo1_03.aspx?RPTSEQ=" & sql(0).RPTSEQ & "&" _
                                                           & "RPTIDX=" & sql(0).RPTIDX & "'" _
                                                           & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')")



                End If
                If (sql(0).RPTTYPE = 1) Then
                    lblAMLO.Text = "ออกรายงาน ปปง.1-01"
                ElseIf (sql(0).RPTTYPE = 2) Then
                    lblAMLO.Text = "ออกรายงาน ปปง.1-02"
                ElseIf (sql(0).RPTTYPE = 3) Then
                    lblAMLO.Text = "ออกรายงาน ปปง.1-03"
                End If
            Else
                btnPrintReport.Visible = True
                'Dim param As String = "{ 'RPTSEQ' : '" & "" & "','RPTIDX' : '" & "" & "'}"
                'btnPrintReport.Attributes.Add("onclick", _
                '            "OpenWindowWithPost('../Form/RptAmlo1_03.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','AMLO_103', " + param + ");")
                'ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", _
                '                                      "window.showModalDialog('../Form/RptAmlo1_03.aspx?RPTSEQ=" & "" & "&" _
                '                                              & "RPTIDX=" & "" & "'" _
                '                                              & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)

                btnPrintReport.Attributes.Add("onclick", _
                            "window.showModalDialog('../Form/RptAmlo1_03.aspx?RPTSEQ=" & "" & "&" _
                                                            & "RPTIDX=" & "" & "'" _
                                                            & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')")


            End If
        End If

      
    End Sub

    Private Sub clearGvIndex()
        grdAmlo.SelectedIndex = -1

    End Sub
    Protected Sub grdAmlo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdAmlo.SelectedIndexChanged
        If (grdAmlo.SelectedIndex = intBeforeItemIndex) Then
            clearGvIndex()
        Else
            Dim txtCodeSEQ As HiddenField = CType(grdAmlo.Rows(grdAmlo.SelectedIndex).FindControl("hdfRPTSEQ"), HiddenField)
            Dim txtCodeIDX As HiddenField = CType(grdAmlo.Rows(grdAmlo.SelectedIndex).FindControl("hdfRPTIDX"), HiddenField)
            If hdfTempRptType.Value = 1 Then
                ' Dim param As String = "{ 'RPTSEQ' : '" & txtCodeSEQ.Value & "','RPTStatus' : 'CheckLoad','RPTIDX' : '" & txtCodeIDX.Value & "'}"
                'Dim param As String = "{ 'RPTSEQ' : '" & txtCodeSEQ.Value & "','' : 'CheckLoad','RPTIDX' : '" & txtCodeIDX.Value & "'}"
                'Dim param As String = "{ 'RPTSEQ' : '" & txtCodeSEQ.Value & "','RPTIDX' : '" & txtCodeIDX.Value & "'}"
                'ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "key", "OpenWindowWithPost('../Form/RptAmlo1_01.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','report_detail', " + param + ");", True)
                ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", _
                                                      "window.showModalDialog('../Form/RptAmlo1_01.aspx?RPTSEQ=" & txtCodeSEQ.Value & "&" _
                                                              & "RPTIDX=" & txtCodeIDX.Value & "'" _
                                                              & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)

            ElseIf hdfTempRptType.Value = 2 Then
                'Dim param As String = "{ 'RPTSEQ' : '" & txtCodeSEQ.Value & "','RPTIDX' : '" & txtCodeIDX.Value & "'}"
                'Dim param As String = "{ 'RPTSEQ' : '" & txtCodeSEQ.Value & "','RPTStatus' : 'CheckLoad','RPTIDX' : '" & txtCodeIDX.Value & "'}"
                'ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "key", "OpenWindowWithPost('../Form/RptAmlo1_02.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','report_detail', " + param + ");", True)
                ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", _
                                                    "window.showModalDialog('../Form/RptAmlo1_02.aspx?RPTSEQ=" & txtCodeSEQ.Value & "&" _
                                                            & "RPTIDX=" & txtCodeIDX.Value & "'" _
                                                            & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)

            ElseIf hdfTempRptType.Value = 3 Then
                'Dim param As String = "{ 'RPTSEQ' : '" & txtCodeSEQ.Value & "','RPTIDX' : '" & txtCodeIDX.Value & "'}"
                'Dim param As String = "{ 'RPTSEQ' : '" & txtCodeSEQ.Value & "','RPTStatus' : 'CheckLoad','RPTIDX' : '" & txtCodeIDX.Value & "'}"
                'ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "key", "OpenWindowWithPost('../Form/RptAmlo1_03.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','report_detail', " + param + ");", True)
                ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", _
                                                                    "window.showModalDialog('../Form/RptAmlo1_03.aspx?RPTSEQ=" & txtCodeSEQ.Value & "&" _
                                                                            & "RPTIDX=" & txtCodeIDX.Value & "'" _
                                                                            & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)

            End If

            'If (grdAmlo.Rows.Count = 1) Then
            clearGvIndex()
            'End If

        End If

    End Sub

    Protected Sub grdAmlo_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdAmlo.SelectedIndexChanging
        intBeforeItemIndex = grdAmlo.SelectedIndex
    End Sub


    Public Sub popup()
        'ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.showModalDialog('../Form/KYCResultBiz.aspx?uniqueID=" & txtBizNo.Text.Trim & "&" _
        '                                    & "BizType=" & ddlBizType.Text & "&" _
        '                                    & "PrefixTH=" & ddlPrefix.Text & "&" _
        '                                    & "NameTh1=" & txtNameTH.Text.Trim & "&" _
        '                                    & "NameEN1=" & txtNameEN.Text.Trim & "&" _
        '                                    & "Nationality=" & ddlNationality.Text & "&" _
        '                                    & "Business1=" & ddlBusiness1.Text & "&" _
        '                                    & "BizOther1=" & txtBizOther1.Text.Trim & "&" _
        '                                    & "Des1=" & txtDes1.Text.Trim & "&" _
        '                                    & "Business2=" & ddlBusiness2.Text & "&" _
        '                                    & "BizOther2=" & txtBizOther2.Text.Trim & "&" _
        '                                    & "Des2=" & txtDes2.Text.Trim & "&" _
        '                                    & "Business3=" & ddlBusiness3.Text & "&" _
        '                                    & "BizOther3=" & txtBizOther3.Text.Trim & "&" _
        '                                    & "Des3=" & txtDes3.Text.Trim & "&" _
        '                                    & "IncomeSource1=" & ddlIncomeSource1.Text & "&" _
        '                                    & "IncomeSource2=" & ddlIncomeSource2.Text & "&" _
        '                                    & "IncomeSource3=" & ddlIncomeSource3.Text & "&" _
        '                                    & "RiskLevel=" & txtRiskLevel.Text.Trim & "&" _
        '                                    & "Reason=" & txtReason.Text.Trim & "'" _
        '                                    & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)


    End Sub
End Class
